package com.unitd.scheduler.test;

import com.unitd.frame.comm.utils.DateUtils;
import com.unitd.scheduler.annotation.ScheduleConf;
import com.unitd.scheduler.job.AbstractJob;
import com.unitd.scheduler.job.JobContext;
import org.apache.commons.lang3.RandomUtils;
import org.springframework.stereotype.Service;

import java.util.Date;

/**
 * @desc 自定义一个Job类执行类,用于执行响应的job任务
 * @filename DemoTask.java
 * @copyright www.unitd.com
 * @author Hudan
 * @version 1.0
 * @date 2016/10/14
 */
@Service
@ScheduleConf(cronExpr = "0/30 * * * * ?", jobName = "demoTask", executeOnStarted = true)
public class DemoTask extends AbstractJob {

	@Override
	public void doJob(JobContext context) throws Exception {
		System.out.println("\n=============\nDemoTask_1=====>" + context.getNodeId() + "--" + DateUtils.format(new Date()) + "\n===============\n");
		Thread.sleep(RandomUtils.nextLong(1000, 2000));
	}

	@Override
	public boolean parallelEnabled() {
		return false;
	}
}